﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>菜单管理</title>
    <#include "/common/link.ftl">

</head>
<body class="hold-transition skin-black sidebar-mini">
<div class="wrapper">
    <#include "/common/navbar.ftl">
    <!--菜单回显-->
    <#assign currentMenu="systemMenu"/>
    <#include "/common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>菜单管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <div style="margin: 20px 0px 0px 10px">
                    <form class="form-inline" id="searchForm" action="/systemMenu/list" method="post">
                        <input type="hidden" name="currentPage" id="currentPage" value="1">
                        <div class="form-group">
                            <label>菜单名称</label>
                            <input type="text" name="name" value="${qo.name}"
                                   class="form-control" placeholder="请输入菜单名称">
                        </div>
                        <div class="form-group">
                            <label>菜单地址</label>
                            <input type="text" name="menuUrl" value="${qo.menuUrl}"
                                   class="form-control" placeholder="请输入菜单地址">
                        </div>
                        <div class="form-group">
                            <label>菜单状态</label>
                            <select class="form-control" name="status" id="statusId">
                                <option value="-1">全部</option>
                                <option value="1">启用</option>
                                <option value="0">禁用</option>
                            </select>
                        </div>
                        <script>
                            $('#statusId').val(${qo.status})
                        </script>
                        <div class="form-group">
                            <label>菜单类型</label>
                            <select class="form-control" name="menuType" id="menuTypeId">
                                <option value="-1">全部</option>
                                <option value="0">目录</option>
                                <option value="1">菜单</option>
                            </select>
                        </div>
                        <script>
                            $('#menuTypeId').val(${qo.menuType});
                        </script>

                        <button type="submit" class="btn btn-primary">
                            <span class="glyphicon glyphicon-search"></span>查询
                        </button>

                        <a href="javascript:" class="btn btn-success btn-input">
                            <span class="glyphicon glyphicon-plus"></span> 添加
                        </a>
                    </form>

                </div>
                <div class="box-body table-responsive ">
                    <table class="table table-hover table-bordered table-striped">
                        <thead>
                        <tr>
                            <th>编号</th>
                            <th>菜单图标</th>
                            <th>菜单类型</th>
                            <th>菜单名称</th>
                            <th>上级菜单</th>
                            <th>菜单URL</th>
                            <th>权限表达式</th>
                            <th>排序</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <#list pageInfo.list as s>
                            <tr>
                                <td>${s_index+1}</td>
                                <td><i class="${s.menuIco!}"></i></td>
                                <td>${s.menuDisplay!}</td>
                                <td>${s.name!}</td>
                                <td>${s.parentName!}</td>
                                <td>${s.menuUrl!}</td>
                                <td>${s.expression!}</td>
                                <td>${s.sort!}</td>
                                <td>${s.statusDisplay!}</td>
                                <td>
                                    <a href="javascript:" class="btn btn-info btn-xs btn-input"
                                       data-json='${s.toJson()}'>
                                        <span class="glyphicon glyphicon-pencil"></span> 编辑
                                    </a>
                                    <#if s.status==0>
                                    <a class="btn btn-xs btn-primary btn-status" data-id='${s.id}' id="start">
                                            <span class="glyphicon glyphicon-phone-alt"></span> 启用</a>
                                    </#if>
                                    <#if s.status==1>
                                        <a class="btn btn-xs btn-danger btn-status" data-id='${s.id}'
                                           id="close">
                                            <span class="glyphicon glyphicon-remove"></span> 禁用</a>
                                    </#if>
                                    <a class="btn btn-xs btn-danger btn-remove" data-id='${s.id}' id="close">
                                        <span class="glyphicon glyphicon-remove"></span> 删除</a>
                                </td>
                            </tr>
                        </#list>

                        </tbody>
                    </table>
                    <!--分页-->
                    <#include "/common/page.ftl">
                </div>

            </div>
        </section>
    </div>
    <#include "/common/footer.ftl">
</div>

<script>
    $(function () {
        // 模态框
        $(".btn-input").click(function () {
            var json = $(this).data('json');
            $('#editForm').clearForm(true);
            $('#editForm select').val('16');

            if (json) {
                $('#editForm input[name=id]').val(json.id);
                // 加个[] 回显 checked类型
                $('#editForm input[name=menuType]').val([json.menuType]);
                $('#editForm input[name=status]').val([json.status]);
                $('#editForm input[name=name]').val(json.name);
                $('#editForm input[name=sn]').val(json.sn);
                $('#editForm select[name=parentId]').val(json.parentId);
                $('#editForm input[name=menuUrl]').val(json.menuUrl);
                $('#editForm input[name=sort]').val(json.sort);
                $('#editForm input[name=menuIco]').val([json.menuIco]);
                $('#editForm input[name=expression]').val(json.expression);
            }

            $("#editModal").modal('show');
        });

        // 异步提交
        $('.btn-submit').click(function () {
            $('#editForm').ajaxSubmit(function (data) {
                if (data.success) {
                    window.location.reload();
                }
            })
        });

        // 启用/禁用
        $('.btn-status').click(function () {
            let id = $(this).data('id');
            Swal.fire({
                title: "是否此菜单状态?",
                text: "此操作是可逆的!",
                icon: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: '确定',
                cancelButtonText: '取消'
            }).then((result) => {
                if (result.value) {
                    // 确定之后 执行这里的代码 同步请求 携带id跳转
                    window.location.href = "/systemMenu/updateStart?id=" + id;
                }
            });

        });
        // 删除
        $('.btn-remove').click(function () {
            let id = $(this).data('id');
            Swal.fire({
                title: "是否删除此菜单?",
                text: "此操作是不可逆的!",
                icon: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: '确定',
                cancelButtonText: '取消'
            }).then((result) => {
                if (result.value) {
                    // 确定之后 执行这里的代码 同步请求 携带id跳转
                    window.location.href = "/systemMenu/delete?id=" + id;
                }
            });

        });
    });

</script>
<!-- Modal -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="myModalLabel">新增/编辑</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
            </div>

            <form id="editForm" action="/systemMenu/saveOrUpdate" method="post">
                <div class="modal-body">
                    <input type="hidden" name="id">
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">菜单类型：</label>
                        <div class="col-sm-7">
                            <label>
                                <input type="radio" name="menuType" value="0" checked>
                                目录
                            </label>
                            <label>
                                <input type="radio" name="menuType" value="1">
                                菜单
                            </label>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">菜单状态类型：</label>
                        <div class="col-sm-7">
                            <label>
                                <input type="radio" name="status" value="0" checked>
                                禁用
                            </label>
                            <label>
                                <input type="radio" name="status" value="1">
                                启用
                            </label>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">菜单名称：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control " name="name"
                                   placeholder="请输入菜单名称"/>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">菜单编号：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control " name="sn"
                                   placeholder="请输入菜单编号"/>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">上级菜单：</label>
                        <div class="col-sm-7">
                            <select class="form-control" name="parentId">
                                <option value="16">请选择目录</option>
                                <#list menuManager as m>
                                    <option value="${m.id}">${m.name}</option>
                                </#list>
                            </select>
                        </div>
                    </div>

                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">菜单URL：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" name="menuUrl"
                                   placeholder="请输入菜单URL">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">菜单序号：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" name="sort"
                                   placeholder="请输入菜单序号">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">菜单图标：</label>
                        <div class="col-sm-7" style="color:lightslategrey">
                            <label>
                                <input type="radio" name="menuIco" value="fa fa-dashboard" checked>
                                <i class="fa fa-dashboard"></i>
                            </label>
                            <label>
                                <input type="radio" name="menuIco" value="fa fa-pie-chart">
                                <i class="fa fa-pie-chart"></i>
                            </label>
                            <label>
                                <input type="radio" name="menuIco" value="fa fa-joomla">
                                <i class="fa fa-joomla"></i>
                            </label>
                            <label>
                                <input type="radio" name="menuIco" value="fa fa-files-o" checked>
                                <i class="fa fa-files-o"></i>
                            </label>
                            <label>
                                <input type="radio" name="menuIco" value="fa fa-edit">
                                <i class="fa fa-edit"></i>
                            </label>
                            <label>
                                <input type="radio" name="menuIco" value="fa fa-laptop">
                                <i class="fa fa-laptop"></i>
                            </label>
                            <label>
                                <input type="radio" name="menuIco" value="fa fa-circle-o">
                                <i class="fa fa-circle-o"></i>
                            </label>
                        </div>

                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">权限表达式：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" name="expression"
                                   placeholder="请输入权限表达式">
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary btn-submit">保存</button>
                </div>
            </form>
        </div>
    </div>
</div>


</body>
</html>
